package com.forum.controller.admin;

import com.forum.dto.FeedBackReplyDTO;
import com.forum.dto.FeedbackDTO;
import com.forum.dto.FeedbackPageQueryDTO;
import com.forum.entity.Feedback;
import com.forum.result.PageResult;
import com.forum.result.Result;
import com.forum.service.FeedbackService;
import com.forum.vo.FeedbackStatusVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import java.util.List;

import static com.forum.constant.MessageConstant.FEEDBACK_SUCCESSFUL;
import static com.forum.constant.MessageConstant.REPLY_SUCCESSFUL;

@Api(tags = "反馈信息接口")
@RestController("AdminFeedbackController")
@RequestMapping("/admin/feedback")
@Slf4j
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @PostMapping("/feedbacks")
    @ApiOperation("查询反馈信息")
    public Result<PageResult> feedbackList(@RequestBody FeedbackPageQueryDTO feedbackPageQueryDTO){
        PageResult pageResult = feedbackService.list(feedbackPageQueryDTO);
        return Result.success(pageResult);
    }
    @PutMapping("/reply")
    @ApiOperation("管理员反馈信息")
    public Result reply(@RequestBody FeedBackReplyDTO feedBackReplyDTO){
        log.info("管理员回复信息：{}",feedBackReplyDTO);
        feedbackService.reply(feedBackReplyDTO);
        return Result.success(REPLY_SUCCESSFUL);
    }

    @ApiOperation("获取各状态的数量")
    @GetMapping("/statistics")
    public Result<FeedbackStatusVO> statistics(){
        FeedbackStatusVO feedbackStatusVO =feedbackService.statistics();
        return Result.success(feedbackStatusVO);
    }
}
